import time

from openai import OpenAI


def call_openai_api():
    client = OpenAI(api_key="sk-9946519d1a3a414eaabd07ade7fc6211", base_url="https://api.deepseek.com")
    # client = OpenAI(api_key="sk-cymvgbmbsjldqigzsihuyxzjmfobiyvwfjbafwoxlvylrssq", base_url="https://api.siliconflow.cn/v1")
    response = client.chat.completions.create(
        model="deepseek-chat",
        # model="deepseek-ai/DeepSeek-R1",
        messages=[
            {"role": "system", "content": "You are a helpful assistant"},
            {"role": "user", "content": "Hello"},
        ],
        max_tokens=1024,
        temperature=0.7,
        stream=False
    )
    print(response.choices[0].message.content)


def schedule_task():
    loop_count = 0  # 初始化计数器
    loop_totalTime = 0
    while True:
        loop_count += 1
        avg_time = 0
        if loop_count != 1:
            avg_time = loop_totalTime / (loop_count - 1)
        print(f"run, 这是第 {loop_count} 轮循环，平均时间：{avg_time}")
        start_time = time.time()  # 记录开始时间
        call_openai_api()
        end_time = time.time()  # 记录结束时间
        execution_time = end_time - start_time  # 计算执行时间
        loop_totalTime += execution_time
        print(f"call_openai_api 方法执行时间: {execution_time} 秒")
        print("-----------------------------------------------------------------")
        # time.sleep(1 * 1)  # 5 minutes in seconds


if __name__ == '__main__':
    schedule_task()
